/*********************************************************************
*
* JLink setup file - Generated by J-Flash ARM V2.16b
*
* Syntax:
*   SetJTAGSpeed(x);           // Sets the JTAG speed, x = speed in kHz (0 = Auto)
*   Delay(x);                  // Waits a given time,  x = delay in milliseconds
*   DisableMMU();              // Disables the MMU
*   Go();                      // Starts the ARM core
*   Halt();                    // Halts the ARM core
*   Reset(x);                  // Resets the target,   x = delay in milliseconds
*   ResetBP0(x);               // Resets the target using breakpoint at address 0
*   ResetADI(x);               // Resets the target using ADI software reset
*   Read8(Addr);               // Reads a 8/16/32 bit value,
*   Read16(Addr);              //   Addr = address to read (as hex value)
*   Read32(Addr);
*   Verify8(Addr, Data);       // Verifies a 8/16/32 bit value,
*   Verify16(Addr, Data);      //   Addr = address to verify (as hex value)
*   Verify32(Addr, Data);      //   Data = data to verify (as hex value)
*   Write8(Addr, Data);        // Writes a 8/16/32 bit value,
*   Write16(Addr, Data);       //   Addr = address to write (as hex value)
*   Write32(Addr, Data);       //   Data = data to write (as hex value)
*   WriteVerify8(Addr, Data);  // Writes and verifies a 8/16/32 bit value,
*   WriteVerify16(Addr, Data); //   Addr = address to write (as hex value)
*   WriteVerify32(Addr, Data); //   Data = data to write (as hex value)
*   WriteRegister(Reg, Data);  // Writes a register
*   WriteJTAG_IR(Cmd);         // Writes the JTAG instruction register
*   WriteJTAG_DR(nBits, Data); // Writes the JTAG data register
*
**********************************************************************
*/

SetJTAGSpeed(30);
//Reset(0);                               // Reset target
Write32(0xFFFF4020, 0x002F0002);        // MOSCEN = 1, OSCOUNT = 47
Delay(20);                              // Wait for PLL
Write32(0xFFFF4020, 0x032F4002);        // Setup PLL to 16MHz
Delay(20);                              // Wait for PLL
Write32(0xFFFF4020, 0x032F4102);        // Setup PLL to 16MHz
Delay(20);                              // Wait for PLL
Write32(0xFFFF4020, 0x032F8102);        // 16Mhz -> 32MHz
Delay(20);                              // Wait for PLL
Write32(0xFFE00018, 0x27A80020);        // AIC set to protected mode
Write32(0xFFE00000, 0x01002529);        // Set up CS0 (Flash)
Write32(0xFFE00004, 0x02002121);        // Set up CS1 (RAM)
Write32(0xFFE00020, 0x00000001);        // Remap internal RAM
Write32(0xffe00024, 0x00000006);        // 2M bytes per Chip Select
SetJTAGSpeed(4000);
